using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using UnityEngine.Scripting;


public class UIEngineService : Service
{
    [Preserve]
    public UIEngineService()
    {

    }

    public override void OnCreate()
    {
        UIEngine.OnLoadPrefabImediately = this.Load;
        UIEngine.OnLoadPrefabAsync = this.LoadAsync;
        UIEngine.RequestBlock = this.OnRequestBlock;
        UIEngine.RequestRemoveBlock = this.OnRequestRemoveBlock;
    }

    void OnRequestBlock()
    {
        BlockManager.Stuff.AddBlock("UIEngine");
    }

    void OnRequestRemoveBlock()
    {
        BlockManager.Stuff.RemoveBlock("UIEngine");
    }

    public override async Task OnPreperAsync()
    {
        //await RefManager.Stuff.Main.GetOrRefAsync<GameObject>("MaskFloating");
        //await RefManager.Stuff.Main.GetOrRefAsync<GameObject>("BubbleMaskFloating");
    }

    async Task<GameObject> LoadAsync(string viewName)
    {
        //var prefab = await RefManager.Stuff.Main.GetOrRefAsync<GameObject>(viewName);
        //return prefab;
        var ret = Resources.Load<GameObject>(viewName);
        if (ret == null)
        {
            ret = Resources.Load<GameObject>(viewName + "/" + viewName);
        }
        return ret;
    }

    GameObject Load(string viewName)
    {
        //var prefab = RefManager.Stuff.Main.Get<GameObject>(viewName);
        //return prefab;
        var ret = Resources.Load<GameObject>(viewName);
        if (ret == null)
        {
            ret = Resources.Load<GameObject>(viewName + "/" + viewName);
        }
        return ret;
    }
}
